//
// Copyright (C) 2011 - 2013  Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1
//#include "stdafx.h"
#include "KernelInterpolation.h"
using namespace Cephei::QL::Math::Interpolations;
#include <gen/QL/Math/Interpolation.h>
using namespace Cephei::QL::Math;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Math::Interpolations::CKernelInterpolation::CKernelInterpolation (boost::shared_ptr<QuantLib::KernelInterpolation>& childNative, Object^ owner) : CInterpolation(CKernelInterpolation::typeid)
{
#ifdef HANDLE
	_phKernelInterpolation = NULL;
#endif
	_ppKernelInterpolation = &childNative;
    _ppInterpolation = new boost::shared_ptr<QuantLib::Interpolation> (boost::dynamic_pointer_cast<QuantLib::Interpolation> (*_ppKernelInterpolation));
}
Cephei::QL::Math::Interpolations::CKernelInterpolation::CKernelInterpolation (QuantLib::KernelInterpolation& childNative, Object^ owner) : CInterpolation(CKernelInterpolation::typeid)
{
#ifdef HANDLE
	_phKernelInterpolation = NULL;
#endif
	_ppKernelInterpolation = new boost::shared_ptr<QuantLib::KernelInterpolation> (&childNative);
    _ppInterpolation = new boost::shared_ptr<QuantLib::Interpolation> (boost::dynamic_pointer_cast<QuantLib::Interpolation> (*_ppKernelInterpolation));
    _KernelInterpolationOwner = owner;
    _InterpolationOwner = owner;
}

Cephei::QL::Math::Interpolations::CKernelInterpolation::CKernelInterpolation (CKernelInterpolation^ copy) : CInterpolation(CKernelInterpolation::typeid)
{
#ifdef HANDLE
	_phKernelInterpolation = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppKernelInterpolation = new boost::shared_ptr<QuantLib::KernelInterpolation> (copy->GetShared());
        _ppInterpolation = new boost::shared_ptr<QuantLib::Interpolation> (boost::dynamic_pointer_cast<QuantLib::Interpolation> (*_ppKernelInterpolation));
    }
}
Cephei::QL::Math::Interpolations::CKernelInterpolation::CKernelInterpolation (PLATFORM::Type^ t) : CInterpolation(CKernelInterpolation::typeid)
{
#ifdef HANDLE
	_phKernelInterpolation = NULL;
#endif
	if (!t->IsSubclassOf(CKernelInterpolation::typeid))
		throw REFNEW Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Math::Interpolations::CKernelInterpolation::CKernelInterpolation (QuantLib::Handle<QuantLib::KernelInterpolation>& childNative, Object^ owner)  : CInterpolation(CKernelInterpolation::typeid)
{
	_phKernelInterpolation = &childNative;
	_ppKernelInterpolation = &static_cast<boost::shared_ptr<QuantLib::KernelInterpolation>>(childNative.currentLink());
    _ppInterpolation = new boost::shared_ptr<QuantLib::Interpolation> (boost::dynamic_pointer_cast<QuantLib::Interpolation> (*_ppKernelInterpolation));
    _KernelInterpolationOwner = owner;
}
Cephei::QL::Math::Interpolations::CKernelInterpolation::CKernelInterpolation (QuantLib::Handle<QuantLib::KernelInterpolation> childNative)  : CInterpolation(CKernelInterpolation::typeid)
{
	_phKernelInterpolation = &childNative;
	_ppKernelInterpolation = &static_cast<boost::shared_ptr<QuantLib::KernelInterpolation>>(childNative.currentLink());
    _ppInterpolation = new boost::shared_ptr<QuantLib::Interpolation> (boost::dynamic_pointer_cast<QuantLib::Interpolation> (*_ppKernelInterpolation));
}
#endif
#ifdef STRUCT
Cephei::QL::Math::Interpolations::CKernelInterpolation::CKernelInterpolation (QuantLib::KernelInterpolation childNative)  : CInterpolation(CKernelInterpolation::typeid)
{
#ifdef HANDLE
	_phKernelInterpolation = NULL;
#endif
	_ppKernelInterpolation = new boost::shared_ptr<QuantLib::KernelInterpolation> (new QuantLib::KernelInterpolation (childNative));
    _ppInterpolation = new boost::shared_ptr<QuantLib::Interpolation> (boost::dynamic_pointer_cast<QuantLib::Interpolation> (*_ppKernelInterpolation));
}
#endif

Cephei::QL::Math::Interpolations::CKernelInterpolation::~CKernelInterpolation ()
{
    if (_ppKernelInterpolation != NULL)
    {
	    delete _ppKernelInterpolation;
        _ppKernelInterpolation = NULL;
    }
}
Cephei::QL::Math::Interpolations::CKernelInterpolation::!CKernelInterpolation ()
{
    if (_ppKernelInterpolation != NULL)
    {
	    delete _ppKernelInterpolation;
    }
}
QuantLib::KernelInterpolation& Cephei::QL::Math::Interpolations::CKernelInterpolation::GetReference ()
{
    if (_ppKernelInterpolation == NULL) throw REFNEW NativeNullException ();
	return **_ppKernelInterpolation;
}
boost::shared_ptr<QuantLib::KernelInterpolation>& Cephei::QL::Math::Interpolations::CKernelInterpolation::GetShared ()
{
    if (_ppKernelInterpolation == NULL) throw REFNEW NativeNullException ();
	return *_ppKernelInterpolation;
}
QuantLib::KernelInterpolation* Cephei::QL::Math::Interpolations::CKernelInterpolation::GetPointer ()
{
    if (_ppKernelInterpolation == NULL) throw REFNEW NativeNullException ();
	return &**_ppKernelInterpolation;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::KernelInterpolation>& Cephei::QL::Math::Interpolations::CKernelInterpolation::GetHandle ()
{
	if (_phKernelInterpolation == NULL)
	{
		_phKernelInterpolation = new Handle<QuantLib::KernelInterpolation> (*_ppKernelInterpolation);
	}
	return *_phKernelInterpolation;
}
#endif
bool Cephei::QL::Math::Interpolations::CKernelInterpolation::HasNative () 
{
	return (_ppKernelInterpolation != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

